package top.yueyazhui.vhr.controller.Sal;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import top.yueyazhui.vhr.bean.Response;
import top.yueyazhui.vhr.model.Salary;
import top.yueyazhui.vhr.service.SalaryService;

import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/Sal/SalSob")
@Api(tags = "工资账套管理")
public class SalSobController {

    @Autowired
    SalaryService salaryService;

    @GetMapping("/")
    @ApiOperation(value = "查询薪资账套", notes = "查询薪资账套")
    public List<Salary> getAll() {
        return salaryService.getAll();
    }

    @PostMapping("/")
    @ApiOperation(value = "创建薪资账套", notes = "创建薪资账套")
    public Response insert(@RequestBody Salary salary) {
        salary.setCreateDate(new Date());
        if(salaryService.insert(salary) == 1) {
            return Response.success("创建成功");
        }
        return Response.error("创建失败");
    }

    @DeleteMapping("/{id}")
    @ApiOperation(value = "删除薪资账套", notes = "删除薪资账套")
    public Response delete(@PathVariable Integer id) {
        if(salaryService.delete(id) == 1) {
            return Response.success("删除成功");
        }
        return Response.error("删除失败");
    }

    @PutMapping("/")
    @ApiOperation(value = "编辑薪资账套", notes = "编辑薪资账套")
    public Response update(@RequestBody Salary salary) {
        if(salaryService.update(salary) == 1) {
            return Response.success("更新成功");
        }
        return Response.error("更新失败");
    }
}
